How to Use ESP32 Deep Sleep Mode for Battery-Powered IoT Projects

The ESP32 is one of the best choices for IoT projects because of its built-in Wi-Fi, Bluetooth, and energy-saving features. In battery-powered applications, deep sleep mode is especially useful for reducing power consumption while the device waits for a trigger to wake up. The following tutorial covers how to implement deep sleep mode, discuss differences from other low-power modes like light sleep and hibernation, configure wake-up sources, and manage data across sleep cycles to help IoT devices with long runtime on a single charge.

esp32 deep sleep mode for battery powered iot projects

Why Use Low Power Modes?

Low-power modes are essential for maximizing battery life in IoT projects. Here are three different modes that you might want to use depending on the needs of your project: Light Sleep, Deep Sleep, or Hibernation. Each mode offers a different power-available functionality trade-off.

ESP32 Power Consumption in Different Modes

esp32 power consumption in different modes

Light Sleep Mode: During this mode, ESP32 remains connected with various peripherals ; it only stops the CPU to reduce power consumption drastically. It is best suited for short sleep cycles.

Deep Sleep Mode: In this mode, ESP32 will power almost everything down except Real Time Clock, drastically lowering power consumption. Therefore, it is perfect for a long-term sleep while retaining some of its memory.

Hibernation Mode: The lowest power consumption but no memory retention. It’s suitable for ultra-low-power applications where memory persistence is unnecessary.

Setting Up ESP32 Deep Sleep Mode

To begin, let’s look at how to configure ESP32 to enter deep sleep. The only component still turned on in this deep-sleep mode is the RTC; it keeps the internal clock running and supports wake-up events.

Example Code for Timer-Based Deep Sleep:

output of deep sleep

Figure 1: Output of Timer-Based Deep Sleep

In this example, a Timer Wake-Up puts the ESP32 into deep sleep for 10 seconds. When the timer finally expires, the device is reset.

Wake-up Sources

The ESP32 could wake up from deep sleep with several sources, as it is highly adaptable in various project needs, such as by timers, GPIOs, and touch sensors.

Wake-up Sources Overview:

wake up source overview

Example: GPIO Wake-up:

output of gpio wakeup

Figure 2: Output of GPIO Wake-up

In this case, the ESP32 wakes up when a button connected to GPIO 33 is pressed. You can also configure multiple GPIOs using the EXT1 wake-up method.

Storing Data Across Deep Sleep Cycles

When the ESP32 wakes up from deep sleep, it resets and starts executing the setup() function again. To retain data across sleep cycles, you can use RTC memory, which stays powered during deep sleep and hibernation.

Using RTC Memory:

using RTC memory to keep tracking data

Example: Storing Boot Count in RTC Memory

storing boot count in rtc memory

Figure 3: Output of Storing Boot Count in RTC Memory

Using RTC_DATA_ATTR, variables like bootCount can persist across sleep cycles. This is useful for applications that require memory retention, such as logging data.

Best Practices for ESP32 deep sleep mode

Here are some simple tips for making the most out of deep sleep mode in your IoT projects:

best practice for deep sleep

Real World Applications of ESP32 deep sleep mode

This results in a deep sleep mode that is nothing less than a game-changer for applications sensitive to power efficiency. Some real-world practical examples of the use cases are listed below:

  1. IoT Remote Sensors: Devices periodically log environmental data and hence only have to wake up for short intervals to transmit data.
  2. Battery-Powered Data Loggers: Devices that record measurement of conditions, such as temperature and humidity, over time.
  3. Wearables: Fitness or health trackers that need to minimize power consumption while still providing functionality when required.

For example, the ESP32-based temperature and humidity logger programmed to wake up every 5 minutes and send the data to the cloud through deep sleep mode may allow it to run for extended use on batteries.

Conclusion

The low-power modes supported by ESP32 are deep sleep, light sleep, and hibernation. These three are the great methods of saving battery life for your IoT projects. You just have to choose the right mode for your needs, set up wake-up triggers, and handle data across sleep cycles. It is also worth mentioning that reducing power consumption to any particular extent basically means accepting trade-offs in the performance of the device. That makes them perfect for applications that require operating autonomously for extended periods and do so efficiently. Building IoT sensors, data loggers, or wearable tech-power consumption optimization with low-power modes will help reach your.

Leave a Comment